<?php

include_once "src/controller/regmanagement/AdminManager.php";

function cleanData(&$str) {
    $str = preg_replace("/\t/", "\\t", $str);
    $str = preg_replace("/\n/", "\\n", $str);
}

try {
    // filename for download
    $filename = "registry_services_consultant_data.csv";

    header("Content-Disposition: attachment; filename=\"$filename\"");
    header("Content-Type: application/vnd.ms-excel");

    $data =  AdminManager::exportConsultantServicesData();

    $flag = false;
    foreach($data as $row) {
        if(!$flag) {
            echo implode(",", array_keys($row)) . "\n";
            $flag = true;
        }
        array_walk($row, 'cleanData');
        echo implode(",", array_values($row)) . "\n";
    }
    
} catch (Exception $e) {

}

exit;
?>
